<template>
	<view>
		<topAlert title="如果您属于政府，媒体，企业等相关机构，可在此申请" />

		<view class="wrap safe-area flex column align-center">
			<view class="wrap-white-bg">
				<block v-for="(item, index) in list" :key="index">
					<block v-if="item.type === 'input' && item.direct === 'row'">
						<rowInput :item="item" v-model="dataInfo[item.key]" />
					</block>

					<block v-else-if="item.type === 'listChoose'">
						<listChoose :item="item" :isRadio="item.isRadio" v-model="dataInfo[item.key]" />
					</block>

					<block v-else-if="item.type === 'upload'">
						<wrapUpload :item="item" v-model="dataInfo[item.key]" />
					</block>
				</block>
			</view>

			<view class="agree-bg flex align-center just-center">
				<view class="choose" @click="isAgree = !isAgree">
					<image v-if="isAgree" :src="$staticImagePath('common/choose_select.png')" />

					<image v-else :src="$staticImagePath('common/choose_normal.png')" />
				</view>

				<view class="f-24">
					<text>点击提交即表示阅读同意</text>
					<text @click="$jump.goHTMLWeb('个人信息使用条款', 'institution_prompt')"
						>《个人信息使用条款》</text
					>
				</view>
			</view>

			<view class="submit-btn theme-gradient-btn f-34" @click="onSubmit">提交审核</view>
		</view>
	</view>
</template>

<script>
	import { getAuthenType, applyAuthenOrg } from "@/API/mine.js";
	import topAlert from "@/components/common/topAlert.vue";
	import rowInput from "@/components/form/rowInput.vue";
	import listChoose from "@/components/form/listChoose.vue";
	import wrapUpload from "@/components/form/upload.vue";
	export default {
		components: {
			topAlert,
			listChoose,
			wrapUpload,
			rowInput,
		},
		data() {
			return {
				list: [
					{
						title: "机构类型",
						type: "listChoose",
						list: [],
						isRadio: true,
						key: "organization_id",
						tips: "请选择机构类型",
					},
					{
						title: "机构名称",
						type: "input",
						list: [],
						mode: "text",
						key: "auth_name",
						place: "请输入机构名称",
						maxlength: 100,
						tips: "请输入机构名称",
						direct: "row",
					},
					{
						title: "机构主体",
						type: "input",
						list: [],
						mode: "text",
						key: "auth_body",
						place: "请输入机构主体",
						maxlength: 100,
						tips: "请输入机构主体",
						direct: "row",
					},
					{
						title: "机构地址",
						type: "input",
						list: [],
						key: "auth_address",
						place: "请输入机构地址",
						maxlength: 100,
						tips: "请输入机构地址",
						direct: "row",
					},
					{
						title: "机构联系人",
						type: "input",
						mode: "text",
						list: [],
						key: "auth_linkname",
						place: "请输入机构联系人",
						maxlength: 10,
						tips: "请输入机构联系人",
						direct: "row",
					},
					{
						title: "机构联系电话",
						type: "input",
						list: [],
						mode: "tel",
						key: "auth_mobile",
						place: "请输入机构联系电话",
						maxlength: 11,
						tips: "请输入机构联系电话",
						direct: "row",
					},
					{
						title: "相关资料",
						desc: "(请上传事业单位相关证明材料或营业执照)",
						type: "upload",
						key: "auth_images",
						tips: "请上传相关资料",
					},
				],
				dataInfo: {
					organization_id: "",
					auth_name: "",
					auth_body: "",
					auth_address: "",
					auth_mobile: "",
					auth_linkname: "",
					auth_images: "",
				},

				isAgree: false, // 同意协议
			};
		},
		onLoad(options) {
			this.getAuthenTypeData();
		},
		methods: {
			/**
			 * 提交审核
			 */
			onSubmit() {
				if (this.$filters.judgeFormList(this.list, this.dataInfo, true)) {
					if (this.isAgree === false) {
						this.$st.show("请阅读并同意《个人信息使用条款》");
						return;
					}
					var obj = this.dataInfo;
					
					this.$throttle(() => {
						applyAuthenOrg(obj).then((res) => {
							this.$st.success("提交成功", () => {
								uni.navigateBack();
							});
						})
					})
				}
			},
			/**
			 * 网络请求
			 */
			getAuthenTypeData() {
				getAuthenType().then((res) => {
					this.list[0].list = res.data;
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	@import "@/css/publish.css";

	.agree-bg {
		margin-top: 50rpx;
		width: 100%;
		gap: 10rpx;
		color: #888888;

		.choose {
			width: 30rpx;
			height: 30rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}
	}
</style>
